package com.ucl.service.flowsearch.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.ucl.dao.flowsearch.SimDao;
import com.ucl.dao.system.SysDictMapper;
import com.ucl.model.common.ApiResult;
import com.ucl.model.entity.flowsearch.FlowDataOption;
import com.ucl.model.request.flowsearch.FSBaseQueryPara;
import com.ucl.model.request.flowsearch.FlowRequestOptionsQueryPara;
import com.ucl.model.request.flowsearch.SimQueryPara;
import com.ucl.model.request.flowsearch.flowDataUpdateRequest;
import com.ucl.model.vo.flowsearch.FSBaseVO;
import com.ucl.model.vo.flowsearch.SimVO;
import com.ucl.model.vo.flowsearch.ColumnVO;
import com.ucl.service.flowsearch.SimService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class SimServiceImpl implements SimService {

    @Autowired
    private SysDictMapper sysDictMapper;

    @Resource
    private SimDao simDao;

    @Override
    public void listPage(Page<SimVO> page, SimQueryPara filter) {
        page.setRecords(simDao.selectSimVOList(page, filter));
    }

    @Override
    public List<ColumnVO> getTableColumnNames(String tableName) {
        return simDao.getTableColumnNames(tableName);
    }

    @Override
    public void insertSimData(List<SimVO> simVOList) {
        simDao.insertSimData(simVOList);
    }

    @Override
    public <T extends FSBaseVO> List<T> getList(FSBaseQueryPara filter) {
        return simDao.getList(filter);
    }

    @Override
    public int flowDataUpdate(flowDataUpdateRequest filter) {
        return simDao.flowDataUpdate(filter);
    }

    @Override
    public int flowDataDelete(flowDataUpdateRequest filter) {
        return simDao.flowDataDelete(filter);
    }

    @Override
    public ApiResult updateFlowInfo(FSBaseVO fsBaseVO) {
        simDao.updateFlowInfo(fsBaseVO);
        return ApiResult.ok();
    }

    @Override
    public ApiResult deleteFlowInfo(FSBaseVO fsBaseVO) {
        fsBaseVO.setDelete(Boolean.TRUE);
        simDao.updateFlowInfo(fsBaseVO);
        return ApiResult.ok();
    }

    @Override
    public ApiResult queryCountryList() {
        List<String> result = simDao.selectCountryList();
        return new ApiResult(result);
    }

    @Override
    public ApiResult querySupplierList() {
        List<String> result = simDao.selectSupplierList();
        return new ApiResult(result);
    }

    @Override
    public ApiResult queryRegionList() {
        List<String> result = simDao.selectRegionList();
        return new ApiResult(result);
    }

    @Override
    public ApiResult queryPeriodList() {
        List<String> result = simDao.selectPeriodList();
        return new ApiResult(result);
    }

    @Override
    public FlowDataOption getRequestOptions(FlowRequestOptionsQueryPara filter) {
        FlowDataOption flowDataOption = new FlowDataOption();
        List<String> categorys = simDao.selectCategoryOptions(filter);
        List<String> suppliers = simDao.selectSupplierOptions(filter);
        List<String> countrys = simDao.selectCountryOptions(filter);
        List<String> regions = simDao.selectRegionOptions(filter);
        List<String> periods = simDao.selectPeriodOptions(filter);

        flowDataOption.setCategorys(categorys);
        flowDataOption.setSuppliers(suppliers);
        flowDataOption.setCountrys(countrys);
        flowDataOption.setRegions(regions);
        flowDataOption.setPeriods(periods);
        return flowDataOption;
    }

}
